import request from "@/services/supcon-chat-tool/api/request";
import { deviceType } from "@/utils/chat";

export interface IToFeedBackParams {
  /**
   * @feedback 类型 thumbsUp: 赞成 ,thumbsDown :反对
   */
  feedback: "thumbsUp" | "thumbsDown";
  /**
   * @id 操作对话 id
   */
  id: string;
  feedbackDescription?: string;
}

interface IFeedBackParams extends IToFeedBackParams {
  sessionId: string;
}

/**
 * @description: 点赞操作
 * @param {IFeedBackParams} params
 * @return {*}
 */
export function handleFeedback(params: IFeedBackParams) {
  return request({
    url: "/cnpc-web/chat-tool-chat/api/conversation/feedback",
    method: "PUT",
    data: {
      data: {
        ...params,
      },
    },
  });
}

interface IGetRecommendedScene {
  id: string;
  name: string;
  type: string;
}
interface IGetRecommendedParams {
  deviceType: keyof deviceType;
  num: number;
  userId: string;
  scene: IGetRecommendedScene;
}
export function getRecommended(params: IGetRecommendedParams) {
  return request({
    url: "/cnpc-web/chat-tool-chat/api/conversation/getRecommended",
    method: "POST",
    data: {
      data: {
        ...params,
      },
    },
  });
}

export function fetchSessions() {
  return request({
    url: "/cnpc-web/chat-tool-chat/api/session/sessions",
    method: "POST",
    data: {
      requestBase: {
        page: "1-50",
        sort: "-createTime",
      },
    },
  });
}

interface IFetchAddSessionParams {
  sessionType?: string;
  summary?: string;
}
export function fetchAddSession({
  sessionType = "text_chat",
  summary = "",
}: IFetchAddSessionParams) {
  return request({
    url: "/cnpc-web/chat-tool-chat/api/session/addSession",
    method: "POST",
    data: {
      data: {
        sessionType: sessionType || "text_chat",
        summary,
      },
    },
  });
}
interface IFetchGenSessionTitle {
  sessionId: string;
  msgId: string;
}
export function fetchGenSessionTitle({
  sessionId,
  msgId,
}: IFetchGenSessionTitle) {
  return request({
    url: `/cnpc-web/chat-tool-chat/api/session/genSessionTitle/${sessionId}/${msgId}`,
    method: "POST",
  });
}

export function fetchDelSession(id: string) {
  return request({
    url: `/cnpc-web/chat-tool-chat/api/session/delSession/${id}`,
    method: "DELETE",
  });
}

interface IFetchUpdateSessionParams {
  id: string;
  summary: string;
}
export function fetchUpdateSession(params: IFetchUpdateSessionParams) {
  return request({
    url: `/cnpc-web/chat-tool-chat/api/session/updateSession`,
    method: "PUT",
    data: {
      data: {
        ...params,
      },
    },
  });
}

export function fetchMessages(id: string) {
  return request({
    url: `/cnpc-web/chat-tool-chat/api/session/messages`,
    method: "POST",
    data: {
      data: {
        sessionId: id,
      },
    },
  });
}
